package cn.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCUnit {
    public static Connection connection(){
        Connection con=null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://:3307/jt_db?characterEncoding=utf-8&serverTimezone=Asia/Shanghai", "root", "root");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return con;
    }
    public static void close(ResultSet resultSet, Statement statement,Connection connection){
        if(resultSet!=null){
            try {
                resultSet.close();
            }catch(Exception e){
                e.printStackTrace();
            }finally {
                resultSet=null;
            }
        }
        if(statement!=null){
            try {
                statement.close();
            }catch(Exception e){
                e.printStackTrace();
            }finally {
                statement=null;
            }
        }
        if(connection!=null){
            try {
                connection.close();
            }catch(Exception e){
                e.printStackTrace();
            }finally {
                connection=null;
            }
        }
    }
}
